﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Emoney.UserTraining.BLL;
using Emoney.UserTraining.Model;

namespace Emoney.UserTraining.Admin.aspx
{
    public partial class OpenMeeting : System.Web.UI.Page
    {
        Traning_NetworkMeetingBLL bll = new Traning_NetworkMeetingBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string id = "";

                if (!string.IsNullOrEmpty(Request["id"]))
                {
                    id = Request["id"];
                    Traning_NetworkMeeting list = bll.GetModel(Convert.ToInt32(id));

                    if (list != null)
                    {
                        string before_time = getTimeToStr(list.class_date.ToString(), list.before_time, -1);
                        string Duration_date = getTimeToStr(list.class_date.ToString(), list.Duration_date, 1);


                        if (list.isCreateMeeting != null && list.isCreateMeeting != "")
                        {
                            if ((System.DateTime.Now > Convert.ToDateTime(before_time)) && (Convert.ToDateTime(Duration_date) > System.DateTime.Now))
                            {
                                Response.Redirect(bll.CreateMeeting(list));
                            }
                        }
                    }
                }

                string mtg_id = "";
                if (!string.IsNullOrEmpty(Request["mtg_id"]))
                {
                    mtg_id = Request["mtg_id"].Trim();
                    List<Traning_NetworkMeeting> list = bll.GetList(mtg_id);

                    if (list.Count > 0)
                    {
                        string before_time = getTimeToStr(list[0].class_date.ToString(), list[0].before_time, -1);
                        string Duration_date = getTimeToStr(list[0].class_date.ToString(), list[0].Duration_date, 1);
                        if ((System.DateTime.Now > Convert.ToDateTime(before_time)) && (Convert.ToDateTime(Duration_date) > System.DateTime.Now))
                        {
                            string url = "http://emoney.cenwave.com/main/user_check_submit.asp?site_id=1062&service_type=0&mtg_id=" + list[0].mtg_id + "&language=Chinese&user_name=luobin&mtg_pwd=" + list[0].mtg_password + "";
                            Response.Redirect(url);
                        }
                    }
                }
            }
        }

        public string getTimeToStr(string time, string num, int zf)
        {
            if (time == null || time == "")
            {
                return "";
            }

            if (num == null || num == "")
            {
                return time;
            }


            return Convert.ToDateTime(time).Add(new TimeSpan(0, 0, Convert.ToInt32(num) * zf, 0, 0)).ToString("yyyy-MM-dd HH:mm:ss");
        }
    }
}